#ifndef PM_TASK_H_INCLUDED
#define PM_TASK_H_INCLUDED

#include "pm/dbobject.h"
#include "pm/criteria.h"
#include <wx/datetime.h>

namespace pm
{

class Task : public db::Object
{
	wxString   m_name;
	double     m_unitCost;
	double     m_quantity;
	wxDateTime m_endDate;
	wxString   m_comment;
	db::ID     m_idProject;
	db::ID     m_idTag;

public:
	static const wxString TABLE_NAME;

public:
	Task();
	Task(wxSQLite3ResultSet& res);

	const wxString& name() const { return m_name; }
	void name(const wxString& name) { m_name = name; }
	
	double unit_cost() const { return m_unitCost; }
	void unit_cost(double c) { m_unitCost = c; }
	
	double quantity() const { return m_quantity; }
	void quantity(double q) { m_quantity = q; }
	
	const wxDateTime& end_date() const { return m_endDate; }
	void end_date(const wxDateTime& date) { m_endDate = date; }

	const wxString& comment() const { return m_comment; }
	void comment(const wxString& cmt) { m_comment = cmt; }
	
	db::ID id_project() const { return m_idProject; }
	void id_project(db::ID idProject) { m_idProject = idProject; }
	
	db::ID id_tag() const { return m_idTag; }
	void id_tag(db::ID idTag) { m_idTag = idTag; }
	
	double cost() const { return m_unitCost * m_quantity; }
	
	bool finished() const { return cost() == 0.0; }

	// DB
	virtual db::update_value_type prepare_insert(wxSQLite3Database& db);
	virtual db::update_value_type prepare_update(wxSQLite3Database& db);
};

typedef std::list<Task> ListTask;

/**
 * \class GetTasksByProject
 */
struct GetTasksByProject : public ICriteriaForEach<Task>
{
	db::ID    m_idProject;
	
	GetTasksByProject(db::ID id_project);
	
	virtual wxSQLite3Statement prepare(wxSQLite3Database& db);
};

/**
 * \class GetTasksTodoByProject
 */
struct GetTasksTodoByProject : public GetTasksByProject
{
	GetTasksTodoByProject(db::ID id_project);
	virtual wxSQLite3Statement prepare(wxSQLite3Database& db);
};

/**
 * \class GetTasksDoneByProject
 */
struct GetTasksDoneByProject : public GetTasksByProject
{
	GetTasksDoneByProject(db::ID id_project);
	virtual wxSQLite3Statement prepare(wxSQLite3Database& db);
};

} // namespace pm

#endif // PM_TASK_H_INCLUDED
